package br.com.acs.CameraIP.controller;

import java.io.Serializable;
import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;

import br.com.acs.CameraIP.dao.CameraDaoImp;
import br.com.acs.CameraIP.model.Camera;
import br.com.acs.CameraIP.util.FacesUtil;

@ManagedBean
@SessionScoped
public class AovivoController implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private Camera camera = new Camera();
	private ArrayList<Camera> camerasCliente;

   
    @PostConstruct
    public void init() {

    	camera = (Camera) FacesUtil.getSessionAttribute("cameraAtiva");
    	camerasCliente = (ArrayList<Camera>) new CameraDaoImp().getCameraPorCliente(camera.getIdCliente());
    }
  
	public String buscaUrlCam() {
		try {
			
			Camera cam = new Camera();
			cam = (Camera) FacesUtil.getSessionAttribute("cameraAtiva");
			return cam.getUrlVideo();
		} catch (Exception ex) {
			FacesUtil.exibirMensagemErro(ex.getMessage());
			return null;
		}
	}
	
	public void cameraSelecionada(AjaxBehaviorEvent event) throws javax.faces.event.AbortProcessingException {
		try {
			
			Camera camS = new Camera();
			camS = new CameraDaoImp().getCamera(camera.getId());
			FacesUtil.setSessionAttribute("cameraAtiva", camS);

		} catch (Exception ex) {
			FacesUtil.exibirMensagemErro(ex.getMessage());
		}
	}

	public ArrayList<Camera> getCamerasCliente() {
		return camerasCliente;
	}
	
	public Long getCameraId(){
		return camera.getId();
	}
	
	public void setCameraId(Long id) {
		this.camera.setId(id);
	}


}
